

import { v4 } from 'uuid'
import { useEffect, useState } from 'react'

const appid = 'wx572054d8408dbcca'
const App = () => {
    const [uuid] = useState(v4())

    useEffect(() => {
        const state = `${uuid}@${appid}`
        const get = `https://cailiaocs.ljkjkf.com/yunshudaping/GetOpenUnionidOrTokenSSE?QRUuid=${uuid}&Type=token`
        const codeData = {
            self_redirect: true,
            id: 'QRcode',
            appid,
            scope: 'snsapi_login',
            response_type: 'code',
            redirect_uri: window.encodeURI('https://transport-redirect.ljkjkf.com'),
            state: state,
            style: 'white',
            href: 'https://image.ljkjkf.com/intellisiteSystem_TieKe/WebTemplate/code.css',
        }

        // var eventSource = new EventSource(get)
        // eventSource.onopen = () => {
        //     console.log('see open')
        //     new window.WxLogin(codeData)
        // }
        // eventSource.onmessage = e => {
        //     // if (e.data.includes('Bearer')) { eventSource.close() }
        //     console.log('sse', e)
        // }
        // eventSource.onerror = () => eventSource.close()
        // return () => { eventSource.close() }
    }, [uuid])

    return (
        <div>
            <div id="QRcode" />
        </div>
    )
}

export default App;